package com.hyts.network.client;

import com.hyts.network.base.ClientFactoryBean;
import com.hyts.network.error.ConnectionException;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;


/**
 * project-name:gitee-extends-toolbox
 * package-name:com.hyts.ext.network.client
 * author:Libo/Alex
 * create-date:2018-10-27 12:38
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: 此类主要用于:NIO服务框架为基础
 */
public abstract class NewClientFactoryBean extends ClientFactoryBean<SocketChannel> {

    /**  
     * @constructor：NewClientFactoryBean  
     * @param port
     * @param client  
     */ 
    public NewClientFactoryBean(int port, SocketChannel client) {
        super(port, client);
    }

    public NewClientFactoryBean(String ip, int port) {
        super(ip, port);
        try {
            this.setClient(SocketChannel.open(new InetSocketAddress(ip,port)));
        } catch (IOException e) {
            throw new ConnectionException("客户端连接失败!",e);
        }
    }

    public NewClientFactoryBean(String ip, int port, SocketChannel client) {
        super(ip, port, client);
    }

    public NewClientFactoryBean(String ip, SocketChannel client) {
        super(ip, client);
    }

    public NewClientFactoryBean(SocketChannel client) {
        super(client);
    }

}
